﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;

namespace WssEvents
{
    /// <summary>
    /// 全局事件管理器，可以通过此管理器发送全局消息事件，方便信息传递
    /// </summary>
    public class GlobalEvent : IDisposable
    {

        /// <summary>
        /// delegate Define
        /// </summary>
        public delegate void GlobalDelegate();
        public delegate void GlobalDelegate<T0>(T0 arg0);
        public delegate void GlobalDelegate<T0, T1>(T0 arg0, T1 arg1);
        public delegate void GlobalDelegate<T0, T1, T2>(T0 arg0, T1 arg1, T2 arg2);
        public delegate void GlobalDelegate<T0, T1, T2, T3>(T0 arg0, T1 arg1, T2 arg2, T3 arg3);
        public delegate void GlobalDelegate<T0, T1, T2, T3, T4>(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4);

        private static EventTarget _target;

        private static EventTarget Target
        {
            get
            {
                if (_target == null)
                    _target = new EventTarget();
                return _target;
            }
            set
            {
                _target = value;
            }
        }

        private static void Listen(string eventType, Delegate Callback)
        {
            Target.Listen(eventType, Callback);
        }

        private static void Remove(string eventType, Delegate Callback)
        {
            Target.Remove(eventType, Callback);
        }

        public static void Addlistener(string eventType, GlobalDelegate Callback)
        {
            Target.Listen(eventType, Callback);

        }
        public static void Addlistener<T0>(string eventType, GlobalDelegate<T0> Callback)
        {
            Target.Listen(eventType, Callback);
        }
        public static void Addlistener<T0, T1>(string eventType, GlobalDelegate<T0, T1> Callback)
        {
            Target.Listen(eventType, Callback);
        }
        public static void Addlistener<T0, T1, T2>(string eventType, GlobalDelegate<T0, T1, T2> Callback)
        {
            Target.Listen(eventType, Callback);
        }
        public static void Addlistener<T0, T1, T2, T3>(string eventType, GlobalDelegate<T0, T1, T2, T3> Callback)
        {
            Target.Listen(eventType, Callback);
        }
        public static void Addlistener<T0, T1, T2, T3, T4>(string eventType, GlobalDelegate<T0, T1, T2, T3, T4> Callback)
        {
            Target.Listen(eventType, Callback);
        }

        public static void Removelistener(string eventType, GlobalDelegate Callback)
        {
            Target.Remove(eventType, Callback);
        }
        public static void Removelistener<T0>(string eventType, GlobalDelegate<T0> Callback)
        {
            Target.Remove(eventType, Callback);
        }
        public static void Removelistener<T0, T1>(string eventType, GlobalDelegate<T0, T1> Callback)
        {
            Target.Remove(eventType, Callback);
        }
        public static void Removelistener<T0, T1, T2>(string eventType, GlobalDelegate<T0, T1, T2> Callback)
        {
            Target.Remove(eventType, Callback);
        }
        public static void Removelistener<T0, T1, T2, T3>(string eventType, GlobalDelegate<T0, T1, T2, T3> Callback)
        {
            Target.Remove(eventType, Callback);
        }
        public static void Removelistener<T0, T1, T2, T3, T4>(string eventType, GlobalDelegate<T0, T1, T2, T3, T4> Callback)
        {
            Target.Remove(eventType, Callback);
        }


        public static void Dispatcher(string eventType)
        {
            Target.Dispatcher(eventType);
        }
        public static void Dispatcher<T0>(string eventType, T0 arg0)
        {
            Target.Dispatcher(eventType, arg0);
        }
        public static void Dispatcher<T0, T1>(string eventType, T0 arg0, T1 arg1)
        {
            Target.Dispatcher(eventType, arg0, arg1);
        }
        public static void Dispatcher<T0, T1, T2>(string eventType, T0 arg0, T1 arg1, T2 arg2)
        {
            Target.Dispatcher(eventType, arg0, arg1, arg2);
        }
        public static void Dispatcher<T0, T1, T2, T3>(string eventType, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
        {
            Target.Dispatcher(eventType, arg0, arg1, arg2, arg3);
        }
        public static void Dispatcher<T0, T1, T2, T3, T4>(string eventType, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
        {
            Target.Dispatcher(eventType, arg0, arg1, arg2, arg3, arg4);
        }

        public static void RemoveTarget(object obj)
        {
            Target.RemoveTarget(obj);
        }

        public static void RemoveAll()
        {
            Target.RemoveAll();
        }

        public void Dispose()
        {
            Target.Dispose();
        }

    }




}



